<?php
/**
 * Frontcontrollerplugin for ACL purposes
 * 
 * @author hcderaad
 * @package EICms
 * @subpackage Acl
 *
 */
class EICms_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract {
	
	/**
	 * The Auth object.
	 *
	 * @var EICms_Auth
	 */
	protected $_auth;
	
	/**
	 * The Acl object
	 *
	 * @var EICms_Acl
	 */
	protected $_acl;
	
	/**
	 * Constructor
	 *
	 * @param EICms_Auth $auth
	 * @param EICms_Acl $acl
	 */
	public function __construct(EICms_Auth $auth,EICms_Acl $acl) {
		$this->_auth = $auth;
		$this->_acl = $acl;
	}
	
	/**
	 * Predispatch method which verifies the requested item against the acl.
	 *
	 * @param Zend_Controller_Request_Abstract $request
	 */
	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		$group = $this->_auth->getIdentity()->group;
		$module = $request->getModuleName();
		if(!$this->_acl->isAllowed($group,$module)) {
			if($group == 'guest') {
				$request->setModuleName('default')
						->setControllerName('index')
						->setActionName('index');
			}
			else {
				$request->setModuleName('default')
						->setControllerName('auth')
						->setActionName('index');
			}
		}
	}
}
?>